/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import junit.framework.TestCase;

import java.text.ParseException;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class RetryAfterHeaderParserTest extends TestCase {
    public RetryAfterHeaderParserTest(String name) {
        super(name);
    }

    //Retry-After: 18000;duration=3600
    public void test() {
        final byte[] data = "Retry-After: 18000;duration=3600".getBytes();
        final RetryAfterHeaderParser parser = new RetryAfterHeaderParser();
        RetryAfterHeaderImpl[] headers;
        try {
            headers = parser.parse(data, 12, data.length);
        } catch (ParseException e) {
            fail(e.getMessage());
            return;
        }
        assertNotNull("The result is null!", headers);
        assertEquals("The length of the result is wrong!", 1, headers.length);
        assertEquals("The retry-after number is wrong!", 18000, headers[0].getRetryAfter());
        assertNull("The comment is wrong!", headers[0].getComment());
        assertEquals("The duration is wrong!", 3600, headers[0].getDuration());
        assertEquals("The string representation is wrong!", "Retry-After: 18000;duration=3600", headers[0].toString());
    }

    //Retry-After: 120 (I'm in a meeting)
    public void test2() {
        final byte[] data = "Retry-After: 120 (I'm in a meeting)".getBytes();
        final RetryAfterHeaderParser parser = new RetryAfterHeaderParser();
        RetryAfterHeaderImpl[] headers;
        try {
            headers = parser.parse(data, 12, data.length);
        } catch (ParseException e) {
            fail(e.getMessage());
            return;
        }
        assertNotNull("The result is null!", headers);
        assertEquals("The length of the result is wrong!", 1, headers.length);
        assertEquals("The retry-after number is wrong!", 120, headers[0].getRetryAfter());
        assertEquals("The comment is wrong!", "I'm in a meeting", headers[0].getComment());
        assertEquals("The duration is wrong!", 0, headers[0].getDuration());
        assertEquals("The string representation is wrong!", "Retry-After: 120 (I'm in a meeting)", headers[0].toString());
    }
}
/*
 * $Log$
 */